#import "ViewController.h"

const NSInteger kMaxWebViews = 1;

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  for (NSInteger i = 0; i < kMaxWebViews; ++i) {
    [self addWebView];
  }
}

- (void)addWebView {
  // Adds a webview that is the width of the device but 1/kMaxWebViews tall.

  CGRect frame = [self.view frame];
  CGFloat height = ceilf(frame.size.height / kMaxWebViews);

  UIView* lastView = [[self.view subviews] lastObject];
  frame.origin.y = CGRectGetMaxY([lastView frame]);
  frame.size.height = height;

  UIWebView* webView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
  NSString* path =[[NSBundle bundleForClass:[self class]]
      pathForResource:@"ViewController"
               ofType:@"html"];
  NSString* html = [NSString stringWithContentsOfFile:path
                                             encoding:NSUTF8StringEncoding
                                                error:nil];
  [self.view addSubview:webView];
  [webView loadHTMLString:html
                  baseURL:[NSURL URLWithString:@"http://localhost/"]];

}

@end
